﻿namespace Dcms.Common
{
    using Dcms.BaseLib;
    using System;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;
    using System.Configuration;

    public class DcmsDataBaseHelper
    {
        private static readonly string DataBaseType = ConfigurationManager.AppSettings["DAL"];

        public static DataTable DataTableList(string cmdText, CommandType cmdType, int ShowCount, int PageNumber)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.DataTableList(cmdText, cmdType, ShowCount, PageNumber);
            return OleDbHelper.DataTableList(cmdText, cmdType, ShowCount, PageNumber);
        }

        public static DataTable DataTableList(string cmdText, CommandType cmdType, int ShowCount, int PageNumber, params object[] commandParameters)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.DataTableList(cmdText, cmdType, ShowCount, PageNumber, (SqlParameter[]) commandParameters);
            return OleDbHelper.DataTableList(cmdText, cmdType, ShowCount, PageNumber, (OleDbParameter[]) commandParameters);
        }

        public static int ExecuteSql(string SQLString, params object[] cmdParms)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.ExecuteSql(SQLString, (SqlParameter[]) cmdParms);
            return OleDbHelper.ExecuteSql(SQLString, (OleDbParameter[]) cmdParms);
        }

        public static DataTable ExecuteTable(string cmdText, CommandType cmdType, params object[] commandParameters)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.ExecuteTable(cmdText, cmdType, (SqlParameter[]) commandParameters);
            return OleDbHelper.ExecuteTable(cmdText, cmdType, (OleDbParameter[]) commandParameters);
        }

        public static int GetDataCount(string cmdText, int DefaultCount)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.GetDataCount(cmdText, DefaultCount);
            return OleDbHelper.GetDataCount(cmdText, DefaultCount);
        }

        public static int GetDataCount(string cmdText, int DefaultCount, params object[] commandParameters)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.GetDataCount(cmdText, DefaultCount, (SqlParameter[]) commandParameters);
            return OleDbHelper.GetDataCount(cmdText, DefaultCount, (OleDbParameter[]) commandParameters);
        }

        public static string GetOneFileValue(string cmdText, string DefaultStr)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.GetOneFileValue(cmdText, DefaultStr);
            return OleDbHelper.GetOneFileValue(cmdText, DefaultStr);
        }

        public static string GetOneFileValue(string cmdText, string DefaultStr, params object[] commandParameters)
        {
            if (DataBaseType == "Dcms.DAL") return SqlHelper.GetOneFileValue(cmdText, DefaultStr, (SqlParameter[]) commandParameters);
            return OleDbHelper.GetOneFileValue(cmdText, DefaultStr, (OleDbParameter[]) commandParameters);
        }
    }
}

